package com.verlet.springbootdemo.simple.nettyrpc.server.codec;

import com.verlet.springbootdemo.simple.nettyrpc.RpcInfo;
import com.verlet.springbootdemo.util.ObjectMapperUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.util.concurrent.EventExecutorGroup;

import java.util.List;

/**
 * @author Verlet
 * @date 2023-08-22 20:31
 */
public class RpcInfoDecoder extends MessageToMessageDecoder<String> {
    @Override
    protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        RpcInfo bean = ObjectMapperUtils.toBean(msg, RpcInfo.class);
        if (bean != null) {
            out.add(bean);
        }
    }
}
